clear

set more 1

use Tpaper_Data_forup 
/* ds = DS number, abatleastwin = at least one claim win, imfexportmil=total export (US dollar in millions)*/
/* ncitedab = #inward citation, priorrulingsum = total number of prior rulings */

tab year, gen(yeardum)
gen limfexport=ln(imfexportmil)
gen laffect=affect*100

correlate extend follow narrow distinguish

/* this is for Table 1 */ 
sum ncitedab laffect priorrulingsum abatleastwin thirdparties
sum extend follow distinguish narrow


/* in 2007 only one obs. drop yeardum7 dummy because of no variation in instruments */
/* these are for Table 2 */

ivpoisson gmm ncitedab yeardum2-yeardum6 yeardum8-yeardum16 (laffect = hsps hcustomsv hsub)
estat overid
estimates store jj1


ivpoisson gmm ncitedab extend follow narrow distinguish abatleastwin yeardum2-yeardum6 yeardum8-yeardum16 priorrulingsum (laffect = hsps hcustomsv hsub)
estat overid
estimates store jj2


ivpoisson gmm ncitedab extend follow narrow distinguish abatleastwin yeardum2-yeardum6 yeardum8-yeardum16 priorrulingsum limfexport thirdparties useudefendant (laffect = hsps hcustomsv hsub)
estat overid
estimates store jj3

/* required to install estout */
estout jj1 jj2 jj3, cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.10 ** 0.05 *** 0.01) title(Inward citations and sentiments) stats(N, fmt(0) label(N)) style(tex)

gen affect_score = laffect


* Scatter plots (Figure 1)
scatter ncitedab year, name(CitationsYear, replace)
scatter affect_score year, name(AffectYear, replace)

* Histogram (Figure 2)
twoway (histogram affect_score if hsps==1, color(gs0%50) frequency) ///
       (histogram affect_score if hsub==1, color(gs8%50) frequency), ///
       legend(order(1 "SPS" 2 "Subsidies")) ///
       name(HistAffect, replace)

* Combine all three
graph combine CitationsYear AffectYear HistAffect 
